package com.ycy.temperature.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.ycy.temperature.R;
import com.ycy.temperature.date.utils.SharedPreferencesUtils;

import butterknife.ButterKnife;

/**
 * Created by XPS on 2017/9/12.
 */

public class SlashActivity extends AppCompatActivity {
    private static final int sleepTime = 1;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
    }


    @Override
    protected void onStart() {
        super.onStart();
        new Thread(new Runnable() {
            public void run() {
                long start = System.currentTimeMillis();
                long costTime = System.currentTimeMillis() - start;
                //等待sleeptime时长
                if (sleepTime - costTime > 0) {
                    try {
                        Thread.sleep(sleepTime - costTime);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //进入主页面
                if (!SharedPreferencesUtils.getBoolean("login", "boolean", false)) {
                    startActivity(new Intent(SlashActivity.this, LoginActivity.class));
                } else {
                    startActivity(new Intent(SlashActivity.this, MainActivity.class));
                }
                finish();
            }
        }).start();
    }

}
